package com.xsmart.goods.dao;

import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public interface BrandDao {

    @Select("<script>" +
            "select brand_id, brand_name, brand_letter, brand_logo, brand_desc, site_url, sort_order, " +
            "is_show, is_delete, audit_status, add_user_id,(SELECT user_name from INFS_ADMIN_USER where user_id = add_user_id) as add_user_name," +
            "date_format(add_time, '%Y-%m-%d %H:%i:%s') as add_time , audit_user_id, " +
            "(SELECT user_name from INFS_ADMIN_USER where user_id = audit_user_id) as audit_user_name, " +
            "date_format(audit_time, '%Y-%m-%d %H:%i:%s') as audit_time from brand " +
            "where 1=1 " +
            "<if test=\"brand_name!=null and brand_name!=''\">and brand_name=#{brand_name}</if>" +
            "<if test=\"audit_status!=null\">and audit_status=#{audit_status}</if>" +
            "</script> ")
    List<Map<String,Object>> queryBrand(Pagination page, Map brandMap);

    @Insert("INSERT INTO brand" +
            "(brand_name," +
            "brand_letter," +
            "brand_logo," +
            "brand_desc," +
            "site_url," +
            "sort_order," +
            "is_show," +
            "is_delete," +
            "audit_status," +
            "add_user_id," +
            "add_time)" +
            "VALUES" +
            "(#{brandMap.brand_name}," +
            "#{brandMap.brand_letter}," +
            "#{brandMap.brand_logo}," +
            "#{brandMap.brand_desc}," +
            "#{brandMap.site_url}," +
            "#{brandMap.sort_order}," +
            "#{brandMap.is_show}," +
            "#{brandMap.is_delete}," +
            "0," +
            "#{brandMap.add_user_id}," +
            "now())")
    int addBrand(@Param("brandMap") Map<String, Object> brandMap);

    @Insert("update brand " +
            "set " +
            "brand_name = #{brandMap.brand_name}, " +
            "brand_letter = #{brandMap.brand_letter}," +
            "brand_logo = #{brandMap.brand_logo}," +
            "brand_desc = #{brandMap.brand_desc}," +
            "site_url = #{brandMap.site_url}," +
            "sort_order = #{brandMap.sort_order}," +
            "is_show = #{brandMap.is_show}," +
            "is_delete = #{brandMap.is_delete}," +
            "audit_status = 0," +
            "add_user_id = #{brandMap.add_user_id}," +
            "add_time = now() " +
            "where brand_id = #{brandMap.brand_id}")
    int modBrand(@Param("brandMap") Map brandMap);

    @Delete("update brand set is_delete = 1 WHERE brand_id=#{brand_id}")
    int delBrand(Integer brand_id);


    @Select( "select brand_id as value, brand_name as label from brand ")
    List<Map<String,Object>> queryAllBrand();

}
